using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerClimbableState : PlayerClimbState
{
    public PlayerClimbableState(Player player, PlayerMoveData playerData, StateMachine stateMachine, string animName) : base(player, playerData, stateMachine, animName)
    {
    }

    bool isStopped;
    Vector3 stopPos;

    public override void Enter()
    {
        base.Enter();
        isStopped = true;
        player.SetVelocityZero();
    }

    public override void LogicUpdate()
    {
        base.LogicUpdate();

        if (yInput != 0)
        {
            if (isStopped)
            {
                isStopped = false;
                player.animator.Play("WallClimb");
            }

            player.SetVelocityY(yInput * playerData.climbVelocity);
            if (yInput == -1) 
            {
                if (isGrounded)
                {
                    stateMachine.ChangeState(player.InAirState);
                }
            }
        }
        else
        {
            if (!isStopped)
            {
                stopPos = player.transform.position;
                isStopped = true;
                player.animator.Play("WallGrab");
            }
            player.transform.position = stopPos;
            player.SetVelocityY(0);
        }
    }

    public override void PhysicsUpdate()
    {
        base.PhysicsUpdate();

        isGrounded = player.CheckLeftFootIfGrounded() || player.CheckLeftFootIfGrounded();
    }
}
